<?php
if($auth->isLogged())
{
	$form = new Form_Form('addSeason');
	//Récupération des infos postées si existante
	$form->setPostedValue($_POST);
	$form->action('admin/season_add.html')
		->setAttributes('id','formSeason');
		
	$form->add('Text','nom')
		->label('Nom<em>*</em> :','block')
		->id('nom')->newLine(false,true)
		->maxlength(150)
		->addValidator('Alnum');
		
	$form->add('Text','date')
		->label('Date de début<em>*</em> :','block')
		->id('date')->newLine(false,true);
		
	$form->add('Submit','envoi')->value('Ajouter')->id('envoi');
			
	if(!$form->isValid($_POST,true))
	{
		$view['form'] = $form->__toString();
		$template = $twig->loadTemplate('admin/season_add.html');
	}
	else
	{
		$season = new PBS_Season();
		if($season->add())
		{
			$view['msg'] = 'La nouvelle saison à été ajouté';
			$view['class'] = 'valid';
		}
		else
		{
			$view['msg'] = 'Une erreur est survenue pendant l\'ajout de la saison';
			$view['class'] = 'error';
		}
		
		$template = $twig->loadTemplate('confirmation/admin_confirm.html');
	}
	echo $template->render($view);
}
else
{
	header('Location: admin/login.html');
}
?>